//
//  TNNotificationViewController.m
//  跑跑快销
//
//  Created by ylife on 14-5-4.
//  Copyright (c) 2014年 ylife. All rights reserved.
//

#import "TNNotificationViewController.h"
#import "TNNotificationCell.h"
#import "TNNewNotificationViewController.h"

@interface TNNotificationViewController ()

@end

@implementation TNNotificationViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"通知";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //添加右键
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]initWithTitle:@"新建通知" style:UIBarButtonItemStylePlain target:self action:@selector(gotoNewNotificationViewController)];
    [self.navigationItem setRightBarButtonItem:rightButton animated:YES];
    
    //更改返回按钮标题
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] init];
    backBarButtonItem.title = @"返回";
    self.navigationItem.backBarButtonItem = backBarButtonItem;
    
    _notificationView = [[TNNotificationView alloc]init];
    self.view = _notificationView;
    _notificationView.notificationTableView.dataSource = self;
    _notificationView.notificationTableView.delegate = self;
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 按钮点击事件
- (void)gotoNewNotificationViewController
{
//    NSLog(@"去新建通知界面");
    [self setHidesBottomBarWhenPushed:YES];
    TNNewNotificationViewController *viewController = [[TNNewNotificationViewController alloc]init];
    [self.navigationController pushViewController:viewController animated:YES];
}

#pragma mark - tableview代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"notificationCell";
    TNNotificationCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[TNNotificationCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    [cell.kindLable setTextColor:[UIColor orangeColor]];
    cell.kindLable.text = @"再接再厉";
    [cell.contentLable setFont:[UIFont systemFontOfSize:20]];
    cell.contentLable.text = @"干的不错!";
    
    
    NSDate *date = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"HH:mm"];
    NSString *dateString = [formatter stringFromDate:date];
    NSString *dayString  = @"今天 ";
    cell.dateLable.text = [dayString stringByAppendingString:dateString];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 90;
}

@end
